{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# hvPlot.errorbars\n",
    "\n",
    "```{eval-rst}\n",
    ".. currentmodule:: hvplot\n",
    "\n",
    ".. automethod:: hvPlot.errorbars\n",
    "```\n",
    "\n",
    "## Backend-specific styling options\n",
    "\n",
    "```{eval-rst}\n",
    ".. backend-styling-options:: errorbars\n",
    "```\n",
    "\n",
    "## Examples\n",
    "\n",
    "### Basic error bars plot\n",
    "\n",
    "Error bars are usually overlaid on another plot using the `*` operator. We set `yerr1` to a variable. When only `yerr1` is set and not `yerr2`, it is displayed as the symmetric error."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame({\"x\": range(1, 4), \"y\": [1, 3, 2], \"yerr\": [0.2, 0.8, 0.5]})\n",
    "\n",
    "df.hvplot.scatter(x=\"x\", y=\"y\") *\\\n",
    "df.hvplot.errorbars(x=\"x\", y=\"y\", yerr1=\"yerr\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Use of `yerr1` and `yerr2`\n",
    "\n",
    "When both `yerr1` and `yerr2` are set, `yerr1` is displayed as the negative error and `yerr2` as the positive error, both as the distance from the center."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame({\"x\": range(1, 4), \"y\": [1, 3, 2], \"yerr1\": 0.5, \"yerr2\": 1})\n",
    "\n",
    "df.hvplot.scatter(x=\"x\", y=\"y\") *\\\n",
    "df.hvplot.errorbars(x=\"x\", y=\"y\", yerr1=\"yerr1\", yerr2=\"yerr2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Inverted error bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame({\"x\": range(1, 4), \"y\": [1, 3, 2], \"yerr\": 0.5})\n",
    "\n",
    "df.hvplot.scatter(x=\"x\", y=\"y\") *\\\n",
    "df.hvplot.errorbars(x=\"x\", y=\"y\", yerr1=\"yerr\", invert=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Bar plot with error bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame({\"x\": [\"A\", \"B\", \"C\"], \"y\": [1, 3, 2], \"yerr\": 0.5})\n",
    "\n",
    "df.hvplot.bar(x=\"x\", y=\"y\", alpha=0.5) *\\\n",
    "df.hvplot.errorbars(x=\"x\", y=\"y\", yerr1=\"yerr\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import hvplot.pandas  # noqa\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.DataFrame({\"x\": [\"A\", \"B\", \"C\"], \"y\": [1, 3, 2], \"yerr\": 0.5})\n",
    "\n",
    "df.hvplot.barh(x=\"x\", y=\"y\", alpha=0.5) *\\\n",
    "df.hvplot.errorbars(x=\"x\", y=\"y\", yerr1=\"yerr\")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
